/*
 * Aboboo Android
 * Copyright (C) 2012 www.aboboo.com
 * 
 */

package com.aboboo.android.player;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;

/**
 * 
 * @author fangpeng
 * 
 * @version 1.0 2013-01-31
 * 
 */
public class MediaButtonReceiver extends BroadcastReceiver {
	private static final String TAG = new String("LyricVolumeKeyReceiver");

	@Override
	public void onReceive(Context context, Intent intent) {
		// MusicPlaybackService service = (MusicPlaybackService)context;
		if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
			KeyEvent key = (KeyEvent) intent
					.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
			if (key.getAction() == KeyEvent.ACTION_DOWN) {
				Log.i(TAG, "OnReceive, getKeyCode = " + key.getKeyCode());
				switch (key.getKeyCode()) {
				case KeyEvent.KEYCODE_HEADSETHOOK:
					context.startService(new Intent(
							MediaPlayerService.ACTION_PLAY_PAUSE));
					break;
				case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
					context.startService(new Intent(
							MediaPlayerService.ACTION_PREVIOUS));
					break;
				case KeyEvent.KEYCODE_MEDIA_NEXT:
					context.startService(new Intent(
							MediaPlayerService.ACTION_NEXT));
					break;
				}
			}
		}
	}
}
